﻿using Infragistics.Windows.DataPresenter;
using Infragistics.Windows.DataPresenter.Events;
using Infragistics.Windows.DockManager.Events;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using VNet.VisiSuite.Controls;
using VNet.VisiSuite.VisiCentral.Controls;
using VNet.VisiSuite.VisiCentral.Models;
using VNet.VisiSuite.VisiCentral.ViewModels;

namespace VNet.VisiSuite.VisiCentral.Views
{
    public partial class MainView : VisiPage
    {
        public MainView()
        {
            InitializeComponent();
        }

        public override IList<VNetMenuItem> BottomMenuItems()
        {
            var viewModel = DataContext as MainViewModel;
            if (viewModel == null) return null;

            return viewModel.BottomMenuItems;
        }

        CellViewModel _selected_cell = null;
        private void cellClicked(object sender, RoutedEventArgs e)
        {
            var btn = (Button)sender;
            if (btn.DataContext is CellViewModel)
            {
                var cell = (CellViewModel)btn.DataContext;

                if (cell.ID != 0 && cell.Enable && !cell.NoData)
                {
                    if (_selected_cell != null && cell != _selected_cell)
                    {
                        _selected_cell.Selected = false;
                    }

                    var vm = DataContext as MainViewModel;
                    if (vm != null)
                    {
                        if (vm.selectCell(cell))
                        {
                            _selected_cell = cell;
                            cell.Selected = true;
                        }
                        else
                        {
                            _selected_cell = null;
                            cell.Selected = false;
                        }
                    }
                }
            }
        }
    }



}
